import { Injectable } from '@angular/core';
import { PreloadingStrategy, Route } from '@angular/router';
import { Observable,of } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class SelectivePreloadingStrategyService implements PreloadingStrategy {

  constructor() { }

  preLoadedModules: string[] = []

  preload(route: Route, load: () => Observable<any>): Observable<any> {
      if(route.path && route.data?.['preload']) {
         this.preLoadedModules.push(route.path)


          console.log('Preloaded: ' + route.path);

          // 添加完预加载模块的路径后，此回调函数会异步加载特性区模块
          return load()
        }else {
            return of(null)
        }
   }
}
